var listName = "list";
var listType = 1; 

function clearList(){
	
  	$("select[id^='"+listName+"']").each(clearChildList);
  	
}
function clearChildList(i, input){
  	if(i > (listType-1)){
  		$(input).remove();
  	}
}

function refreshCateg(string){
	var id=$("#"+listName+"_"+string).val();
	
	if(id=="" || id==0){ 
		if(string=='one'){		
  			listType = 1;
  			$("#categId").val($("#cateIds:checked").val());
  		}else if(string=='two'){
  			listType = 2;
  			$("#categId").val($("#list_one").val());
  		}else if(string=='thr'){
  			listType = 3;
  			$("#categId").val($("#list_two").val());
  		}else if(string=='for'){
		   	$("#categId").val($("#list_thr").val());
  		}
  		clearList();
  		return;
  	} 
	$("#categId").val(id);
	switch(string){
		case "one":
		$.ajax({
			type: "get",
		   	url: "get_provCateg1.htm",
		   	cache: false,
		  	data: {parent_id:id},
		   	success: function(msg){	  
		   		listType=1;
		   		clearList();
		   		
				if($(msg).find("content").length>0){			
					var htmlText = "<select id='list_two' onchange=refreshCateg('two');></select>";
					$("#menuList").append(htmlText);
					var slt = $("#list_two");
					$('<option>',{val:"0",text:"请选择",selected:"selected"}).appendTo(slt);
					$(msg).find("content").each(function(i){
						var data = $(this); 
						$('<option>',{val:data.find("id").text(),text:data.find("name").text()}).appendTo(slt);
					});
				}
				
		   	}
		});
		break;
		
		case "two":
		$.ajax({
			type: "get",
		   	url: "get_provCateg1.htm",
		   	cache: false,
		  	data: {parent_id:id},
		   	success: function(msg){	  
		   		listType=2;
		   		clearList();
		   		
				if($(msg).find("content").length>0){			
					var htmlText = "<select id='list_thr' onchange=refreshCateg('thr');></select>";
					$("#menuList").append(htmlText);
					var slt = $("#list_thr");
					$('<option>',{val:"0",text:"请选择",selected:"selected"}).appendTo(slt);
					$(msg).find("content").each(function(i){
						var data = $(this); 
						$('<option>',{val:data.find("id").text(),text:data.find("name").text()}).appendTo(slt);
					});
				}
				
		   	}
		});
		break;
		
		case "thr":
		$.ajax({
			type: "get",
		   	url: "get_provCateg1.htm",
		   	cache: false,
		  	data: {parent_id:id},
		   	success: function(msg){	  
		   		listType=3;
		   		clearList();
		   		
				if($(msg).find("content").length>0){			
					var htmlText = "<select id='list_for' onchange=refreshCateg('for');></select>";
					$("#menuList").append(htmlText);
					var slt = $("#list_for");
					$('<option>',{val:"0",text:"请选择",selected:"selected"}).appendTo(slt);
					$(msg).find("content").each(function(i){
						var data = $(this); 
						$('<option>',{val:data.find("id").text(),text:data.find("name").text()}).appendTo(slt);
					});
				}
				
		   	}
		});
		break;
		
		case "for":
		$.ajax({
			type: "get",
		   	url: "get_provCateg1.htm",
		   	cache: false,
		  	data: {parent_id:id},
		   	success: function(msg){	  
		   		listType=4;
		   		clearList();
		   		
				if($(msg).find("content").length>0){			
					var htmlText = "<select id='list_fiv' onchange=refreshCateg('fiv')></select>";
					$("#menuList").append(htmlText);
					var slt = $("#list_fiv");
					$('<option>',{val:"0",text:"请选择",selected:"selected"}).appendTo(slt);
					$(msg).find("content").each(function(i){
						var data = $(this); 
						$('<option>',{val:data.find("id").text(),text:data.find("name").text()}).appendTo(slt);
					});
				}
				
		   	}
		});
		break;
		case "fiv":
		break;
	}
}

function modefySelect(){
	var id = $("input[name='cateIds']:checked").val();
	$("#categId").val(id);
	$.ajax({
		type: "get",
	   	url: "get_provCateg1.htm",
	   	cache: false,
	  	data: {parent_id:id},
	   	success: function(msg){
	   		listType=1;
		   	clearList();
	   		$("#list_one").empty();
	   		var slt = $("#list_one");
	   		$('<option>',{val:"0",text:"请选择",selected:"selected"}).appendTo(slt);
	   		if($(msg).find("content").length>0){
		   		$(msg).find("content").each(function(i){
		   			var data = $(this); 
					$('<option>',{val:data.find("id").text(),text:data.find("name").text()}).appendTo(slt);
		   		});
		   	}
	   	}
	});
}